package com.mogist.hqc.module.personal.presenter

import com.mogist.hqc.entitys.BaseResponse
import com.mogist.hqc.entitys.response.CollectListVo
import com.mogist.hqc.module.personal.contract.CollectContract
import com.mogist.hqc.mvp.HttpDto
import com.mogist.hqc.mvp._PresenterImpl
import com.mogist.hqc.util.Constant
import talex.zsw.basecore.util.JsonTool
import talex.zsw.basecore.util.RegTool
import talex.zsw.basecore.view.dialog.sweetalertdialog.SweetAlertDialog
import talex.zsw.basecore.view.other.RxToast

/**
 * 作用：收藏列表
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
class CollectPresenter(view: CollectContract.View) : _PresenterImpl<CollectContract.View, BaseResponse>(
        view), CollectContract.Presenter
{
    override fun requestSuccess(response: BaseResponse, http: HttpDto)
    {
        when (http.url)
        {
            Constant.COLLECT_LIST ->
            {
                mView.disLoading()
                if (response.success)
                {
                    mView.disDialog()
                    val vo = JsonTool.getObject(response.content, CollectListVo::class.java)
                    mView.bindList(vo)
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE, "获取收藏列表失败", response.message)
                }
            }
            Constant.COLLECT_ADD    ->
            {
                mView.disDialog()
                if (response.success)
                {
                    RxToast.success("取消收藏成功")
                    mView.cancelSuccess()
                }
                else
                {
                    if (RegTool.isEmpty(response.message))
                    {
                        RxToast.error("取消收藏失败，${response.message}")
                    }
                    else
                    {
                        RxToast.error("取消收藏失败")
                    }
                }
            }
        }
    }

    override fun requestError(msg: String?, httpDto: HttpDto)
    {
        if (httpDto.url == Constant.COLLECT_ADD)
        {
            mView.disDialog()
            RxToast.error("取消收藏失败，请检查网络后重试")
        }
        else
        {
            mView.disLoading()
            super.requestError(msg, httpDto)
        }
    }
}